Generate a date and time as a stringΒΆ
Generate a date and time as a string.
import datetime
now = datetime.datetime.now()
# Make a note of the date and time in a string
# Date and time in string :
# 2016-11-05 11:24:24 PM
datestr = "# In string: " + now.strftime("%Y-%m-%d %H:%M:%S %p")
print(datestr)
Output:
# In string: 2018-10-15 07:22:26 AM